//
//  JLShowPersonMsgViewController.m
//  JLStyleApp
//
//  Created by LvJianfeng on 15/10/10.
//  Copyright © 2015年 JLStyle. All rights reserved.
//

#import "JLShowPersonMsgViewController.h"

#define AVATARWH 130.f

@interface JLShowPersonMsgViewController () <UIScrollViewDelegate>
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UIImageView *avatarImageView;
/**
 *  weak
 */
@property (nonatomic, weak) UILabel *nameLabel;
@property (nonatomic, weak) UIView *backgroundView;

@end

@implementation JLShowPersonMsgViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.scrollView];
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.scrollView addSubview:self.topView];
    [self.scrollView addSubview:self.avatarImageView];
    
    self.title = @"基本信息";
    //set data
    [self settingPersonalData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView == self.scrollView) {
        CGFloat x = scrollView.contentOffset.x;
        [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
            if (x > 0) {
                if (x>ScreenWidth/2) {
                    self.avatarImageView.center = CGPointMake(ScreenWidth/2+x-120, self.avatarImageView.center.y);
                }else{
                    self.avatarImageView.center = CGPointMake(ScreenWidth/2+x, self.avatarImageView.center.y);
                }
            }
            
            if (x<ScreenWidth) {
                CGFloat alpha = (1-(ScreenWidth-x)/ScreenWidth);
                CGFloat scale = -alpha+1;
                self.backgroundView.alpha = scale;
                if (scale<=0.5) {
                    return;
                }
                self.avatarImageView.transform = CGAffineTransformMakeScale(scale, scale);
            }
            
        } completion:^(BOOL finished) {
            if (x>=ScreenWidth) {
                self.navigationItem.hidesBackButton = YES;
            }else{
                self.navigationItem.hidesBackButton = NO;
            }
        }];
    }
}


- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if (scrollView == self.scrollView) {
        NSInteger currentPage = scrollView.contentOffset.x / scrollView.frame.size.width;
        switch (currentPage) {
            case 0:
                self.title = @"基本信息";
                break;
            case 1:
                self.title = @"工作经验";
                break;
                
            default:
                break;
        }
    }
    
}
/**
 *  设置基本信息数据
 */
- (void)settingPersonalData{
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.avatarImageView.center.y+AVATARWH/2+10, ScreenWidth, 30)];
    nameLabel.text = @"测试用户";
    nameLabel.textAlignment = NSTextAlignmentCenter;
    nameLabel.textColor = [UIColor customGrayColor];
    nameLabel.font = [UIFont systemFontOfSize:18];
    [self.scrollView addSubview:nameLabel];
    self.nameLabel = nameLabel;
    
    UILabel *otherLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, nameLabel.center.y+10+5, ScreenWidth, 20)];
    otherLabel.text = @"女 24岁 本科";
    otherLabel.textAlignment = NSTextAlignmentCenter;
    otherLabel.textColor = [UIColor customGrayColor];
    otherLabel.font = [UIFont systemFontOfSize:12];
    [self.scrollView addSubview:otherLabel];
    
    UILabel *schoolLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, otherLabel.center.y+10, ScreenWidth, 30)];
    schoolLabel.text = @"北京外国语大学北京外国语大学";
    schoolLabel.numberOfLines = 0;
    schoolLabel.textAlignment = NSTextAlignmentCenter;
    schoolLabel.textColor = [UIColor customGrayColor];
    schoolLabel.font = [UIFont systemFontOfSize:14];
    [self.scrollView addSubview:schoolLabel];
    
    CGFloat Y = schoolLabel.center.y+15;
    UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, Y+5, ScreenWidth, ScreenHeight-Y)];
    backgroundView.backgroundColor = GlobalColor;
    [self.scrollView addSubview:backgroundView];
    self.backgroundView = backgroundView;
    
    CGFloat tipW = ScreenWidth/3;
    CGFloat valueW = ScreenWidth-tipW;
    UILabel *phone = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, tipW, 20)];
    [phone fontSize:14 fontColor:[UIColor whiteColor] textAlignment:NSTextAlignmentRight text:@"手机："];
    [self.backgroundView addSubview:phone];
    
    UILabel *email = [[UILabel alloc] initWithFrame:CGRectMake(0, phone.center.y+30, tipW, 20)];
    [email fontSize:14 fontColor:[UIColor whiteColor] textAlignment:NSTextAlignmentRight text:@"邮箱："];
    [self.backgroundView addSubview:email];
    
    //专业
    UILabel *speciality = [[UILabel alloc] initWithFrame:CGRectMake(0, email.center.y+30, tipW, 20)];
    [speciality fontSize:14 fontColor:[UIColor whiteColor] textAlignment:NSTextAlignmentRight text:@"专业："];
    [self.backgroundView addSubview:speciality];
    
    UILabel *address = [[UILabel alloc] initWithFrame:CGRectMake(0, speciality.center.y+30, tipW, 20)];
    [address fontSize:14 fontColor:[UIColor whiteColor] textAlignment:NSTextAlignmentRight text:@"地址："];
    [self.backgroundView addSubview:address];
    
    UILabel *phoneValue = [[UILabel alloc] initWithFrame:CGRectMake(tipW, 40, valueW, 20)];
    [phoneValue fontSize:14 fontColor:[UIColor whiteColor] textAlignment:NSTextAlignmentLeft text:@"13813828035"];
    [self.backgroundView addSubview:phoneValue];
    
    UILabel *emailValue = [[UILabel alloc] initWithFrame:CGRectMake(tipW, phone.center.y+30, valueW, 20)];
    [emailValue fontSize:14 fontColor:[UIColor whiteColor] textAlignment:NSTextAlignmentLeft text:@"邮箱："];
    [self.backgroundView addSubview:emailValue];
    
    //专业
    UILabel *specialityValue = [[UILabel alloc] initWithFrame:CGRectMake(tipW, email.center.y+30, valueW, 20)];
    [specialityValue fontSize:14 fontColor:[UIColor whiteColor] textAlignment:NSTextAlignmentLeft text:@"专业："];
    [self.backgroundView addSubview:specialityValue];
    
    UILabel *addressValue = [[UILabel alloc] initWithFrame:CGRectMake(tipW, speciality.center.y+30, valueW, 40)];
    [addressValue fontSize:14 fontColor:[UIColor whiteColor] textAlignment:NSTextAlignmentLeft lines:0 text:@"我的家在东北得松花江上得啊啊得啊得你知道啊"];
    [self.backgroundView addSubview:addressValue];
    
    UILabel *job = [[UILabel alloc] initWithFrame:CGRectMake(0, backgroundView.bounds.size.height-120, ScreenWidth, 60)];
    [job fontSize:18 fontColor:[UIColor whiteColor] textAlignment:NSTextAlignmentCenter lines:0 text:@"我的家在东北得松"];
    [self.backgroundView addSubview:job];
    
    
    UILabel *jobTip = [[UILabel alloc] initWithFrame:CGRectMake(0, job.center.y-30-5, ScreenWidth, 20)];
    [jobTip fontSize:14 fontColor:[UIColor whiteColor] textAlignment:NSTextAlignmentCenter lines:0 text:@"求职岗位"];
    [self.backgroundView addSubview:jobTip];
}

/**
 *  设置工作经验数据
 */
- (void)settingWorkData{
    
}

/**
 *  设置教育经历数据
 */
- (void)settingEduData{}

/**
 *  设置项目经验数据
 */
- (void)settingProjectData{}

/**
 *  设置期望工作数据
 */
- (void)settingHopeWorkData{}

/**
 *  设置技能评价数据
 */
- (void)settingSkillData{}

/**
 *  设置自我描述数据
 */
- (void)settingMeData{}

/**
 *  设置作品展示数据
 */
- (void)settingProductionData{}

#pragma mark lazyload

- (UIScrollView *)scrollView{
    if (_scrollView==nil) {
        _scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
        _scrollView.contentSize = CGSizeMake(ScreenWidth*8, ScreenHeight-64);
        _scrollView.showsVerticalScrollIndicator = YES;
        _scrollView.showsHorizontalScrollIndicator = YES;
        _scrollView.pagingEnabled = YES;
        _scrollView.bounces = YES;
        _scrollView.delegate = self;
    }
    return _scrollView;
}
- (UIView *)topView{
    if (_topView==nil) {
        UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth*8, 80)];
        topView.backgroundColor = GlobalColor;
        _topView = topView;
    }
    return _topView;
}

- (UIImageView *)avatarImageView{
    if (_avatarImageView==nil) {
        _avatarImageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth/2-AVATARWH/2, self.topView.center.y+40-AVATARWH/2, AVATARWH, AVATARWH)];
        _avatarImageView.layer.cornerRadius = AVATARWH/2;
        _avatarImageView.layer.borderWidth = 2;
        _avatarImageView.layer.borderColor = [UIColor whiteColor].CGColor;
        _avatarImageView.clipsToBounds = YES;
        _avatarImageView.image = [UIImage imageNamed:@"avatar"];
    }
    return _avatarImageView;
}
@end
